package SimpleNotepad;

public class SimpleNotepad implements iNotepad
{
	private Page[] pages;

	public SimpleNotepad(int numberOfPages)
	{
		if(numberOfPages > 0)
		{
			pages = new Page[numberOfPages];
			for(int i = 0; i < pages.length; i++)
			{
				pages[i] = new Page(String.valueOf(i+1));
			}
		}
		else
		{
			System.out.println("Wrong input");
		}
	}
	
	@Override
	public void addText(int pageNumber, String newText) 
	{
		if(validatePage(pageNumber))
		{
			pages[pageNumber-1].addText(newText);
		}
	}
	
	private boolean validatePage(int pageNumber)
	{
		return pageNumber > 0 && pageNumber <= pages.length;
	}

	@Override
	public void replaceTextInPage(int pageNumber, String newText) 
	{
		if(validatePage(pageNumber))
		{
			pages[pageNumber-1].deleteText();
			pages[pageNumber-1].addText(newText);
		}
		
	}

	@Override
	public void deleteText(Page selectedPage) 
	{
		for(int i = 0; i < pages.length; i++)
		{
			if(pages[i].equals(selectedPage))
				selectedPage.deleteText();
		}
	}

	@Override
	public void viewPages() 
	{
		for(int i = 0; i < pages.length; i++)
		{
			System.out.println(pages[i].getPageInfo());
		}
		
	}
	
}
